#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int longestConsecutive(vector<int>& nums) {
        unordered_set<int> hash;
        int ans = 0;
        for (auto& e : nums) {
            hash.insert(e);
        }
        for (auto& x : nums) {
            if (!hash.count(x - 1)) {
                int y = x;
                while (hash.count(y + 1)) y++;
                ans = max(ans, y - x + 1);
            }
        }
        return ans;
    }
};